package com.hy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hy.medicine.MedicineEvaluation;
import com.hy.medicine.vo.MedicineEvaluationVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 药品评价
 */
@Mapper
public interface MedicineEvaluationMapper extends BaseMapper<MedicineEvaluation> {
    /**
     * 根据药品id查询评价
     *
     * @param medicineId
     * @return
     */
    List<MedicineEvaluationVO> selectEvaluationsWithUser(Integer medicineId);

    // /**
    //  * 根据订单id查询评价
    //  * @param orderId
    //  * @return
    //  */
    // @Select("SELECT COUNT(*) FROM medicine_evaluation WHERE order_id = #{orderId}")
    // boolean existsByOrderId(@Param("orderId") Integer orderId);

    /**
     * 点赞
     * @param evaluationId
     */
    @Update("UPDATE medicine_evaluation SET like_count = like_count + 1 WHERE evaluation_id = #{evaluationId}")
    void incrementLikeCount(@Param("evaluationId") Integer evaluationId);

    /**
     * 取消点赞
     * @param evaluationId
     */
    @Update("UPDATE medicine_evaluation SET like_count = like_count - 1 WHERE evaluation_id = #{evaluationId}")
    void decrementLikeCount(@Param("evaluationId") Integer evaluationId);

    /**
     * 回复
     * @param evaluationId
     */
    @Update("UPDATE medicine_evaluation SET reply_count = reply_count + 1 WHERE evaluation_id = #{evaluationId}")
    void incrementReplyCount(@Param("evaluationId") Integer evaluationId);






}
